package com.enterprise.projectManager.resource;

import com.enterprise.projectManager.model.Log;
import com.enterprise.projectManager.model.Response;
import com.enterprise.projectManager.service.implemention.IndexServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static java.time.LocalDateTime.now;
import static java.util.Map.of;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;

@RestController
@RequiredArgsConstructor
@RequestMapping("/crebas/index")
public class IndexResource {
    private final IndexServiceImpl indexService;
    @GetMapping("/getData")
    public ResponseEntity<Response> getData() {
        return ResponseEntity.ok(
                Response.builder()
                        .timeStamp(now())
                        .data(of("indexData1",indexService.getIndexData()))
                        .message("首页数据1")
                        .status(OK)
                        .statusCode(OK.value())
                        .build()
        );
    }

    @GetMapping("/getProjectBuildingProcess")
    public ResponseEntity<Response> getProjectBuildingProcess() {
        return ResponseEntity.ok(
                Response.builder()
                        .timeStamp(now())
                        .data(of("buildingProcess",indexService.getProjectBuildingProcess()))
                        .message("首页数据buildingProcess")
                        .status(OK)
                        .statusCode(OK.value())
                        .build()
        );
    }

    @GetMapping("/getPostponedRatio")
    public ResponseEntity<Response> getPostponedRatio() {
        return ResponseEntity.ok(
                Response.builder()
                        .timeStamp(now())
                        .data(of("postponedRatio",indexService.getPostponedRatio()))
                        .message("首页数据postponedRatio")
                        .status(OK)
                        .statusCode(OK.value())
                        .build()
        );
    }
    @GetMapping("/getProjectBuildingPhaseRatio")
    public ResponseEntity<Response> getProjectBuildingPhaseRatio() {
        return ResponseEntity.ok(
                Response.builder()
                        .timeStamp(now())
                        .data(of("buildingPhaseRatio",indexService.getProjectBuildingPhaseRatio()))
                        .message("首页数据BuildingPhaseRatio")
                        .status(OK)
                        .statusCode(OK.value())
                        .build()
        );
    }
}
